package com.leen.news.controller;

import com.leen.common.vo.ResponseVO;
import com.leen.common.vo.ResultVO;
import com.leen.news.dto.YxSystemAttachmentDTO;
import com.leen.news.entity.YxSystemAttachment;
import com.leen.news.service.YxSystemAttachmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/news/ysattac")
public class YxSystemAttachmentController {
    @Autowired
    private YxSystemAttachmentService yxSystemAttachmentService;

    @GetMapping(value = "/data")
    @ApiOperation(value = "分页查询")
    public ResultVO<ResponseVO> search(YxSystemAttachmentDTO yxSystemAttachmentDTO){
        ResponseVO search = this.yxSystemAttachmentService.search(yxSystemAttachmentDTO);
        return ResultVO.success(search);
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "新增附件")
    public ResultVO<String> add(@RequestBody @Valid YxSystemAttachment yxSystemAttachment){
        return this.yxSystemAttachmentService.insert(yxSystemAttachment);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改附件")
    public ResultVO<String> update(@RequestBody @Valid YxSystemAttachment yxSystemAttachment){
        return this.yxSystemAttachmentService.updateById(yxSystemAttachment);
    }

    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除附件")
    public ResultVO<String> delete(@RequestBody @Valid YxSystemAttachment yxSystemAttachment){
        yxSystemAttachment.setIsDel(true);
        return this.yxSystemAttachmentService.updateById(yxSystemAttachment);
    }
}
